package com.qxsx.midi.activity.study;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.qxsx.midi.R;
import com.qxsx.midi.activity.main.MainActivity;
import com.qxsx.midi.adapter.StudySearchRltListAdapter;
import com.qxsx.midi.model.StudyListItem;

import java.util.ArrayList;
import java.util.List;

public class StudyManSearchActivity extends Activity {

    EditText edtSearch;
    ListView listView;          //
    List<StudyListItem> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        String id = getIntent().getExtras().getString("id");
//        Log.d("study detail activity", id);
        setContentView(R.layout.activity_study_man_search);

        edtSearch = (EditText) findViewById(R.id.man_search);

        edtSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                edtSearch.setCursorVisible(true);
                edtSearch.requestFocus();
            }
        });

        // 搜索框完成,跳转相应的 Activity
        edtSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    Log.e("edi", "waaa");
                    edtSearch.setCursorVisible(false);
                } else {
                    Log.e("edi", "wasdfffffffffffffffffffffffff");
                }
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(edtSearch.getWindowToken(), 0);

//                Intent intent = new Intent(this, class);
//                startActivity(intent);
                return true;
            }
        });

        final Activity act = this;
        // 返回键
        LinearLayout btnBack = (LinearLayout) findViewById(R.id.man_back);
        btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
                overridePendingTransition(R.anim.slide_left_in, R.anim.slide_right_out);
//                Intent intent = new Intent(act, MainActivity.class);
//                startActivity(intent);
            }
        });


        // 列表
        list = new ArrayList<>();
        StudySearchRltListAdapter listAdapter = new StudySearchRltListAdapter(this, list);
        listView = (ListView) findViewById(R.id.man_search_list);
        listView.setAdapter(listAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(act, MidiManDetailsActivity.class);
                startActivity(intent);
            }
        });
    }
}
